package com.yang.pojo.mapper;

import com.yang.io.Resources;
import com.yang.pojo.User;
import com.yang.sqlSession.SqlSession;
import com.yang.sqlSession.SqlSessionFactory;
import com.yang.sqlSession.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class IUserMapperImpl implements IUserMapper {
    @Override
    public List<User> findAll() throws Exception {
        InputStream resourcesAsSteam = Resources.getResourcesAsSteam("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourcesAsSteam);
        SqlSession sqlSession = build.openSession();
        List<User> list = sqlSession.selectList("User.selectList");
        return list;
    }

    @Override
    public User findByCondition(User user) throws Exception {
        InputStream resourcesAsSteam = Resources.getResourcesAsSteam("sqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourcesAsSteam);
        SqlSession sqlSession = build.openSession();
        User user2 = sqlSession.selectOne("User.selectOne", user);
        System.out.println(user2.toString());
        return user2;
    }
}
